<!-- @format -->

<template>
	<div class="ma-content-block lg:flex justify-between p-4">
		<!-- CRUD 组件 预报单  非集装箱 -->
		<ma-crud
			:options="options"
			:columns="columnsYBDZC"
			ref="crudRefYBDZC"
			tableRef='tableRefxx'
			v-if="
				(inforow?.pick_type == 1 || inforow?.pick_type == 2) &&
				inforow?.transport_type == 2
			"
		>
			<template #summaryCell="{ column, record, rowIndex }">
				{{
					
					column.dataIndex == "prediction.goods_name"
					? "合计"
					: column.dataIndex == 'pick_weight'
					?(record[column.dataIndex] - 0).toFixed(3)
					:record[column.dataIndex]
				}}
			</template>
		</ma-crud>
		<!-- CRUD 组件 仓库  普通提货 -->
		<ma-crud
			:options="options"
			:columns="columnsCKPT"
			ref="crudRefCKPT"
			v-if="
				(inforow?.pick_type == 3 || inforow?.pick_type == 4) &&
				inforow?.transport_type == 2 
			"
		>
			<template #warehouse_user_detail_id="{ record }">
				<a-tag style="margin-top: 5px" color="blue" v-if="record.wareuserdetail.warehouse_log_chu != null"
					>{{ record.wareuserdetail.warehouse_log_chu?.horizontal_position }}-{{
						record.wareuserdetail.warehouse_log_chu?.release_position
					}}-{{ record.wareuserdetail.warehouse_log_chu?.reaches_position }}</a-tag
				>
				<div v-else></div>
			</template>

			<template #summaryCell="{ column, record, rowIndex }">
				{{
					column.dataIndex == "wareuserdetail.goods_name"
						? "合计"
						: column.dataIndex == 'pick_weight'
						?(record[column.dataIndex] - 0).toFixed(3)
						:record[column.dataIndex]
				}}
			</template>
		</ma-crud>
	</div>
</template>
<script setup>
	import { ref, reactive } from "vue";
	import predictionDeriverOrderDetail from "@/api/prediction/predictionDeriverOrderDetail";
	import { Message } from "@arco-design/web-vue";
	import tool from "@/utils/tool";
	import * as common from "@/utils/common";
	const crudRefYBDZC = ref();
	const crudRefCKPT = ref();
	const crudRefCKJZ = ref();
	const order_id = ref();
	const inforow = ref();

	const open = (row, inforows) => {
		order_id.value = row.id;
		inforow.value = inforows;
		if (row.pick_type == 1 || row.pick_type == 2) {
			if (row.transport_type == 1) {
			} else {
				setTimeout(() => {
					// crudRefYBDZC.value.crudSearchRef.resetSearch();
					crudRefYBDZC.value.requestData();
				},10);
			}
		} else if (row.pick_type == 3 || row.pick_type == 4) {
			if(row.transport_type == 2){
				setTimeout(() => {
					crudRefCKPT.value.requestData();

				},10);
			}
			
		}
	};

	const options = reactive({
		id: "flyos_prediction_deriver_order_detail",
		// rowSelection: {
		//   showCheckedAll: true
		// },
		pk: "id",
		
		autoRequest:false,
		bordered: { cell: true },
		operationColumn: false,
		operationWidth: 160,
		// expandSearch:false,
		formOption: {
			viewType: "modal",
			width: 600,
		},
		api: predictionDeriverOrderDetail.getList,
		exports: {
			show: true,
		},
		beforeRequest: (params) => {
			params.order_id = order_id.value;
			params.order = "created_at";
			params.orderType = "desc";
		},
		afterRequest: (params) => {
      params.map((v, i) => {
		v.pick_weight = (v.pick_weight -0 ).toFixed(3)
      });
    },
	});

	// 预报单  非集装箱
	let columnsYBDZC = reactive([
		{
			title: "ID",
			dataIndex: "id",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			commonRules: {
				required: true,
				message: "请输入ID",
			},
		},
		{
			title: "品名",
			dataIndex: "prediction.goods_name",
			align: "center",
			formType: "input",
			// search: true,
		},
		{
			title: "发站",
			dataIndex: "prediction.producer",
			align: "center",
			formType: "input",
			// search: true,
		},
		{
			title: "车号",
			dataIndex: "prediction.car_no",
			align: "center",
			formType: "input",
			// search: true,
		},
		

		{
			title: "提货数量（件）",
			dataIndex: "pick_number",
			formType: "input",
			align: "center",
			search: false,
		},
		{
			title: "提货重量（吨）",
			dataIndex: "pick_weight",
			formType: "input",
			align: "center",
			search: false,
		},
		{
			title: "创建时间",
			dataIndex: "created_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
		{
			title: "更新时间",
			dataIndex: "updated_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
		{
			title: "删除时间",
			dataIndex: "deleted_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
	]);
	// 仓库  普通提货
	let columnsCKPT = reactive([
		{
			title: "ID",
			dataIndex: "id",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			commonRules: {
				required: true,
				message: "请输入ID",
			},
		},
		
		{
			title: "品名",
			dataIndex: "wareuserdetail.goods_name",
			align: "center",
			formType: "input",
			// search: true,
		},
		
		{
			title: "仓库",
			dataIndex: "wareuserdetail.warehouse_log_chu.warehouse.name",
			align: "center",
			formType: "input",
			search: false,
		},
		{
			title: "仓位（横-纵-层）",
			dataIndex: "warehouse_user_detail_id",
			align: "center",
			formType: "input",
			search: false,
		},
		{
			title: "提货数量",
			dataIndex: "pick_number",
			align: "center",
			formType: "input",
			search: false,
		},
		{
			title: "提货重量",
			width: 150,
			dataIndex: "pick_weight",
			align: "center",
			formType: "input",
			search: false,
		},
	]);
	

	defineExpose({ open });
</script>
<script>
	export default { name: "prediction:deriverOrderDetail" };
</script>
